﻿//*************************Get Width, Height of Screen*************************
function getScreenWidth() {
    return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
}

function getScreenHeight() {
    return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight;
}

//*************************End Get Width, Height of Screen*************************

//*************************Popup Modal*************************
//Get Rad Window
function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz az well)
    return oWindow;
}

function GetPopupModal(index) {
    if (windowManagerID == '')
        windowManagerID = 'ctl00_ctl00_uxWindowManager';
    var windowManager = $find(windowManagerID);
    windowManager = windowManager.get_windows();
    var modalWindow = null;
    if (windowManager != null) {
        modalWindow = windowManager[index];
    }
    return modalWindow;
}
var coreSub, coreSubUrl, coreSubWidth, coreSubHeight, coreSubPosX, coreSubPosY;
function ShowPopupModalChild(index, url, width, height, posX, posY) {
    coreSub = index;
    coreSubUrl = url;
    coreSubWidth = width;
    coreSubHeight = height;
    coreSubPosX = posX;
    coreSubPosY = posY;
    setTimeout('DoCheatOpenSubModalChild()', 500);
    return false;
}

function DoCheatOpenSubModalChild() {
    OpenPopupModal(coreSub, coreSubUrl, coreSubWidth, coreSubHeight, coreSubPosX, coreSubPosY);
}
function OpenPopupModal(index, url, width, height, posX, posY) {    
    if (windowManagerID == '')
        windowManagerID = 'ctl00_ctl00_uxWindowManager';
    var windowManager = $find(windowManagerID);
    windowManager = windowManager.get_windows();
    if (windowManager != null) {
        var modalWindow = windowManager[index];      
        //Set width, height of modal window
        var scrW = getScreenWidth();
        var scrH = getScreenHeight();
        var sizeRate = 0.40;
       
        if (width == null) width = scrW * sizeRate;
        if (height == null) height = scrH * sizeRate;
        modalWindow.setSize(width, height);
        //Set position(x,y) of modal window
        if (posX == null && posY == null) {
            posX = (scrW - width) / 2 + Math.max(document.body.scrollWidth, document.documentElement.scrollWidth);
            posY = (scrH - height) / 2 + Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
        }
        modalWindow.MoveTo(posX, posX);
        
        modalWindow.setUrl(url);
        modalWindow.show();
    }
}
function ClosePopupModal(index) {
    if (index == null)
        GetRadWindow().Close();
    else {
        if (windowManagerID == '')
            windowManagerID = 'ctl00_ctl00_uxWindowManager';
        var windowManager = $find(windowManagerID);
        windowManager = windowManager.get_windows();
        if (windowManager != null)
            windowManager[index].close();
        else
            GetRadWindow().Close();
    }
    return false;
}

function PopupModalClose(sender, eventArgs) {
    var obj = sender.get_contentFrame().contentWindow;
    if (obj != null && obj.master_closeModalEvent != null) obj.master_closeModalEvent();
}

//*************************End Popup Modal*************************


//Trim string
String.prototype.trim = function() {
    a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
};
// Print in RadWindow
function RadWindowPrint() 
{
    var oWnd = GetRadWindow();
    var content = oWnd.GetContentFrame().contentWindow;
    var printDocument = content.document;

    if (document.all) {
        // support IE to print fully
        printDocument.execCommand("Print");
    }
    else {
        // other browsers
        content.print();
    }
    return false;
}
 function ReloadRadGrid(gridId){
     var masterTable = $find(gridId).get_masterTableView();
     if(masterTable!=null)
        masterTable.rebind();
}
function AdjustModalSize(){
    var modalWindow = null; 
    if (window.radWindow)
    modalWindow = window.radWindow; else if (window.frameElement.radWindow)
    modalWindow = window.frameElement.radWindow; 
    modalWindow.autoSize(true);
}

